home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: delta / whiteline CD Series - delta.iso / tools / anwender / astrolog / sources / placalc.h < prev    next >
C/C++ Source or Header  |  1995-11-25  |  18KB  |  473 lines

  1. /*
  2. ** Astrolog (Version 4.40) File: placalc.h
  3. **
  4. ** IMPORTANT NOTICE: The graphics database and chart display routines
  5. ** used in this program are Copyright (C) 1991-1995 by Walter D. Pullen
  6. ** (astara@u.washington.edu). Permission is granted to freely use and
  7. ** distribute these routines provided one doesn't sell, restrict, or
  8. ** profit from them in any way. Modification is allowed provided these
  9. ** notices remain with any altered or edited versions of the program.
  10. **
  11. ** The main planetary calculation routines used in this program have
  12. ** been Copyrighted and the core of this program is basically a
  13. ** conversion to C of the routines created by James Neely as listed in
  14. ** Michael Erlewine's 'Manual of Computer Programming for Astrologers',
  15. ** available from Matrix Software. The copyright gives us permission to
  16. ** use the routines for personal use but not to sell them or profit from
  17. ** them in any way.
  18. **
  19. ** The PostScript code within the core graphics routines are programmed
  20. ** and Copyright (C) 1992-1993 by Brian D. Willoughby
  21. ** (brianw@sounds.wa.com). Conditions are identical to those above.
  22. **
  23. ** The extended accurate ephemeris databases and formulas are from the
  24. ** calculation routines in the program "Placalc" and are programmed and
  25. ** Copyright (C) 1989,1991,1993 by Astrodienst AG and Alois Treindl
  26. ** (alois@azur.ch). The use of that source code is subject to
  27. ** regulations made by Astrodienst Zurich, and the code is not in the
  28. ** public domain. This copyright notice must not be changed or removed
  29. ** by any user of this program.
  30. **
  31. ** Initial programming 8/28,30, 9/10,13,16,20,23, 10/3,6,7, 11/7,10,21/1991.
  32. ** X Window graphics initially programmed 10/23-29/1991.
  33. ** PostScript graphics initially programmed 11/29-30/1992.
  34. ** Last code change made 1/29/1995.
  35. */
  36.  
  37. #include "astrolog.h"
  38.  
  39.  
  40. #define EPHE_PATH EPHE_DIR
  41. #define HUGE8 1.7E+308     /* biggest value for REAL8 */
  42.  
  43. extern int lrz_file_posit(double,FILE ** );
  44. extern int chi_file_posit(double,FILE ** );
  45. extern int outer_hel();
  46. extern void longreorder();
  47. extern int inpolq(int,int,double,double *,double *,double *);
  48.  
  49. #ifdef PLACALC
  50. /************************************************************
  51. $Header: placalc.h,v 1.4 93/03/22 10:08:39 alois Exp $
  52. definitions and constants for planetary routines
  53.  
  54. ATTENTION: PLACALC USERS ON MSDOS:
  55. See the note close to the end of this file regarding EPHE_PATH.
  56.  
  57. ---------------------------------------------------------------
  58. | Copyright Astrodienst AG and Alois Treindl, 1991, 1993.     |
  59. | The use of this source code is subject to regulations made  |
  60. | by Astrodienst Zurich. The code is NOT in the public domain.|
  61. |                                                             |
  62. | This copyright notice must not be changed or removed        |
  63. | by any user of this program.                                |
  64. ---------------------------------------------------------------
  65. ************************************************************/
  66.  
  67. /************************************************************
  68. $Header: ourdef.h,v 1.2 91/11/16 16:21:37 alois Exp $
  69. definitions and constants for all Astrodienst C programs
  70. contains only declarations and #defines, no global variables.
  71. auto-dectection of MSDOS (TURBO_C or MS_C) or HPUNIX
  72. ************************************************************/
  73.  
  74. #ifdef MSDOS  /* already defined by some DOS compilers */
  75. #undef MSDOS
  76. #define MSDOS 1
  77. #endif
  78.  
  79. #ifdef __TURBOC__ /* defined by turboc */
  80. #ifndef ATARI                    /* Ajout Abel PHILIPPE */
  81. #ifndef MSDOS
  82. #define MSDOS 1
  83. #endif
  84. #endif
  85. #define TURBO_C
  86. #endif
  87.  
  88. #ifndef ATARI                /* Ajout Abel PHILIPPE */
  89. #if MSDOS
  90. #define HPUNIX 0
  91. #ifndef TURBO_C
  92. #define MS_C /* assume Microsoft C compiler */
  93. #endif
  94. #else
  95. #define MSDOS 0
  96. #define HPUNIX 1
  97. #ifndef _HPUX_SOURCE
  98. #define _HPUX_SOURCE
  99. #endif
  100. #endif
  101. #endif
  102.  
  103. #include <stdlib.h>
  104. #if HPUNIX
  105. #ifndef MAC
  106. #include <unistd.h>
  107. #endif
  108. #endif
  109.  
  110. #ifndef OK 
  111. #define OK 0
  112. #define ERR (-1)
  113. #endif
  114.  
  115.  
  116. #define UCHP (unsigned char*)  /* used for casting *char  */
  117. #define UCP (unsigned char*)  /* used for casting *char  */
  118. #define SCP (char*)     /* used for casting *unsigned char */
  119. #define UCHAR unsigned char
  120.  
  121. #if HPUNIX
  122. #ifndef MAC
  123. #include <malloc.h>
  124. #endif
  125. typedef double  REAL8;  /* real with at least 64 bit precision */
  126. typedef float   REAL4;  /* real with at least 32 bit precision */
  127. typedef long     INT4;   /* signed integer with at least 32 bit precision */
  128. typedef unsigned long UINT4; 
  129. /* unsigned integer with at least 32 bit precision */
  130. typedef int     INT2;   /* signed integer with at least 16 bit precision */
  131. typedef int     INT1;   /* signed integer with at least 8  bit precision */
  132. #ifndef dbd_VERSION /* db_vista defines boolean in vista.h already */
  133. typedef int     BOOLEAN;
  134. #endif
  135. typedef unsigned short UINT2; /* unsigned 16 bits */
  136. #define ABS4  abs   /* abs function for long */
  137. #endif
  138.  
  139. #if MSDOS 
  140. #ifdef TURBO_C
  141. #include <alloc.h>    /* MSC needs malloc ! */
  142. #else
  143. #include <malloc.h>
  144. #endif
  145. typedef double  REAL8;  /* real with at least 64 bit precision */
  146. typedef float   REAL4;  /* real with at least 32 bit precision */
  147. typedef long    INT4;   /* signed integer with at least 32 bit precision */
  148. typedef unsigned long UINT4;
  149.                         /* unsigned integer with at least 32 bit precision */
  150. typedef int     INT2;   /* signed integer with at least 16 bit precision */
  151. typedef int     INT1; /* signed integer with at least 8  bit precision */
  152. typedef int     BOOLEAN;
  153. typedef unsigned int UINT2; /* unsigned 16 bits */
  154. #define ABS4  labs    /* abs function for long */ 
  155. #endif
  156.  
  157. #ifdef ATARI                /* Ajout Abel PHILIPPE pour Pure C */
  158. typedef double  REAL8;  /* real with at least 64 bit precision */
  159. typedef float   REAL4;  /* real with at least 32 bit precision */
  160. typedef long    INT4;   /* signed integer with at least 32 bit precision */
  161. typedef unsigned long UINT4;
  162.                         /* unsigned integer with at least 32 bit precision */
  163. typedef int     INT2;   /* signed integer with at least 16 bit precision */
  164. typedef int     INT1; /* signed integer with at least 8  bit precision */
  165. typedef int     BOOLEAN;
  166. typedef unsigned int UINT2; /* unsigned 16 bits */
  167. #define ABS4  labs    /* abs function for long */ 
  168. #endif
  169.  
  170. #define COS8 cos
  171. #define SIN8 sin
  172. #define ASIN8 asin
  173. #define TAN8 tan
  174. #define ATAN8 atan
  175. #define ATAN28 atan2
  176. #define EXP10(x) pow(10.0, (x))
  177. #define ABS8(x) fabs(x)
  178.  
  179. #define TANERRLIMIT 1.0E-10     /* used to check for arguments close to pi */
  180. #define NEAR_ZERO   1.0E-16     /* used to compare for divisors close to 0 */
  181. #define BIGREAL     1.0E+38
  182.  
  183. #define DEGTORAD 0.0174532925199433
  184. #define RADTODEG 57.2957795130823
  185.  
  186. typedef INT4 centisec;   /* centiseconds used for angles and times */
  187. #define CS   (centisec)  /* use for casting */
  188. #define CSEC centisec    /* use for typing */
  189.  
  190. #define DEG     (360000L)   /* degree expressed in centiseconds */
  191. #define DEG7_30 (2700000L)  /* 7.5 degrees */
  192. #define DEG15   (15 * DEG)
  193. #define DEG24   (24 * DEG)
  194. #define DEG30   (30 * DEG)
  195. #define DEG60   (60 * DEG)
  196. #define DEG90   (90 * DEG)
  197. #define DEG120  (120 * DEG)
  198. #define DEG150  (150 * DEG)
  199. #define DEG180  (180 * DEG)
  200. #define DEG270  (270 * DEG)
  201. #define DEG360  (360 * DEG)
  202.  
  203. #define CSTORAD 4.84813681109536E-08 /* centisec to rad: pi / 180 /3600/100 */
  204. #define RADTOCS 2.06264806247096E+07 /* rad to centisec 180*3600*100/pi */
  205.  
  206. #define DEG2MSEC 3600000.0  /* degree to milliseconds */
  207. #define DEG2CSEC 360000.0   /* degree to centiseconds */
  208.  
  209. #define SEC2CSEC 100  /* seconds to centiseconds */
  210.  
  211. #define CS2DEG    (1.0/360000.0)  /* centisec to degree */
  212. #define CS2CIRCLE (CS2DEG/360.0)  /* centisec to circle */
  213. #define AU2INT    1e7             /* factor for long storage of A.U. */
  214.  
  215. #define CSMIN 6000L
  216. #define CSSEC 100L
  217.  
  218. #define SINDEG(x) sin(DEGTORAD * (x))
  219. #define COSDEG(x) cos(DEGTORAD * (x))
  220. #define TANDEG(x) tan(DEGTORAD * (x))
  221. #define SINCS(x)  sin((double)(CSTORAD * (x)))
  222. #define COSCS(x)  cos((double)(CSTORAD * (x)))
  223. #define TANCS(x)  tan((double)(CSTORAD * (x)))
  224.  
  225. /*************************************************************
  226. Exported functions:
  227.  
  228. In all functions the variable jd_ad indicates the use of
  229. Astrodienst relative julian days, and jd the use of absolute
  230. julian days.
  231. *************************************************************/
  232.  
  233. extern int nacalc();
  234. extern int calcserv();
  235. extern void helup(REAL8);
  236. extern void togeo(REAL8,REAL8,REAL8,REAL8,REAL8,REAL8 *,REAL8 *);
  237. extern int calc(int planet,REAL8 jd_ad,int flag,REAL8 * alng,REAL8 * arad,
  238.                                      REAL8 * alat,REAL8 * alngspeed);
  239. extern int rel_geo();
  240. extern int hel(int planet,REAL8 t,REAL8 *al,REAL8 *ar,REAL8 *az, REAL8 *alp,
  241.                                      REAL8 *arp,REAL8 *azp);
  242. extern int moon(REAL8 *,REAL8 *,REAL8 *);
  243. extern REAL8 sidtime();
  244. extern REAL8 smod8360(REAL8);
  245. extern REAL8 mod8360(REAL8);
  246. extern REAL8 diff8360(REAL8,REAL8);
  247. extern REAL8 test_near_zero(REAL8);
  248. extern REAL8 deltat(REAL8 jd_ad);
  249. extern void to_mean_ekl();
  250. extern int afl2planet();
  251. extern void disturb(register struct kor *k,REAL8 *,REAL8 *,REAL8,REAL8,REAL8);
  252. extern REAL8 fnu(REAL8,REAL8,REAL8);
  253.  
  254. /*************************************************************
  255. exported variables
  256. *************************************************************/
  257.  
  258. extern REAL8 meanekl;
  259. extern REAL8 ekl;
  260. extern REAL8 nut;
  261.  
  262. extern struct elements { /* actual elements at time thelup */
  263.   REAL8 tj,     /* centuries from epoch */
  264.   lg,     /* mean longitude in degrees of arc*/
  265.   pe,     /* longitude of the perihelion in degrees of arc*/
  266.   ex,     /* excentricity in degrees of arc*/
  267.   kn,     /* longitude of node in degrees of arc*/
  268.   in,     /* inclination of the orbit in degrees of arc*/
  269.   ma;     /* mean anomaly in degrees of arc*/
  270. } el [];
  271.  
  272. extern char *ephe_path;
  273.  
  274. /*************************************************************
  275. definitions
  276. *************************************************************/
  277.  
  278. /*
  279. * planet index numbers, used to identify a planet in calc() and
  280. * other related functions.
  281. */
  282. #define CALC_ONLY_ECL_NUT -1  /* pseudo planet index for calls to calc */
  283. #define SUN 0   /* used synonymously for earth too */
  284. #define EARTH 0
  285. #define MOON  1
  286. #define MERCURY 2
  287. #define VENUS 3
  288. #define MARS  4
  289. #define JUPITER 5
  290. #define SATURN  6
  291. #define URANUS  7
  292. #define NEPTUNE 8
  293. #define PLUTO 9
  294. #define LASTPLANET PLUTO
  295. #define MEAN_NODE  10
  296. #define TRUE_NODE  11
  297. #define CHIRON     12
  298. #define CALC_N     13 /* number of planets in placalc module */
  299. #define LILITH     13 /* Lilith is separate, not included in standard set
  300.   of placalc planets. This is required because
  301.   otherwise some string server calls would
  302.   suddenly return a higher number of fields. */
  303.  
  304. /*
  305. * in a bitlist flag each planet is represented by a bit;
  306. * all 13 defined planets can be called at once with
  307. * LILITH is not automatically included
  308. */
  309. #define CALC_ALL_PLANET_BITS ((1 << 13) - 1) /* bits 0..12 set */
  310.  
  311. #define J2000 2451545.0 /* Epoch of JPL ephemeris DE200, absolute */
  312. #define J1950  2433282.423  /* Epoch of JPL ephemeris DE102 */
  313. #define JUL_OFFSET 2433282.0  /* offset of Astrodienst relative Julian date */
  314. #define EPOCH1850 -36524.0  /* jupiter,saturn 0 jan 1850, 12:00 */
  315. #define EPOCH1900 -18262.0  /* inner planets  0 jan 1900, 12:00 */
  316. #define EPOCH1950  0.0    /* pluto    0 jan 1950, 12:00 */
  317.                 /* this is the origin of the Astrodienst
  318.                    relative julian calendar system */
  319. #define EPOCH1960 3653.0 /* uranus,neptune 1 jan 1960, 12:00 */
  320.  
  321. #define ENDMARK 99 /* used to mark the end of disturbation terms */
  322.  
  323. #define NODE_INTERVAL 0.005        /* days, = 7m20s */
  324. #define MOON_SPEED_INTERVAL 0.0001 /* 8.64 seconds later */
  325.  
  326. /*
  327. * flag bits used in calc and calcserv
  328. */
  329. #define CALC_BIT_HELIO 1   /* geo/helio */
  330. #define CALC_BIT_NOAPP 2   /* apparent/true positions */
  331. #define CALC_BIT_NONUT 4   /* true eq. of date/ mean equ. of date */
  332. #define CALC_BIT_EPHE  8   /* universal/ephemeris time */
  333. #define CALC_BIT_SPEED 16  /* without/with speed */
  334. #define CALC_BIT_BETA  32  /* without/with latitude */
  335. #define CALC_BIT_RGEO  64  /* without/with relative rgeo */
  336. #define CALC_BIT_RAU   128 /* without/with real radius */
  337. #define CALC_BIT_MUST_USE_EPHE 256 /* epheserv may not use calc */
  338. #define CALC_BIT_MAY_USE_EPHE  512 /* calcserv may use ephread */
  339.  
  340. /* ephemeris file path for MSDOS */
  341.  
  342. /*****************************************************************************
  343. ATTENTION: PLACALC USERS ON MSDOS:
  344.  
  345. EPHE_PATH indicates where the ephemeris files LRZ_nnn and CHI_nnn
  346. are found in you system.
  347. EPHE_PATH is only used once at the beginning of placalc.c to initialize
  348. the global variable ephe_path.
  349.  
  350. If you do not have the ephemeris files in \PAIR\EPHE, you must do one of
  351. two things:
  352. - change the #define statement below to point to your ephemeris directory
  353. - OR change the global char *ephe_path before  you call any placalc
  354. function.
  355. Take care, that ephe_path ends NOT with the directory character ('\' in DOS).
  356. *****************************************************************************/
  357.  
  358. #define EPHE_STEP 80              /* days step in LRZ ephe */
  359. #define EPHE_DAYS_PER_FILE 100000L /* days per ephe file */
  360. #define EPHE_OUTER "LRZ5_"        /* file name prefix */
  361. #define EPHE_OUTER_BSIZE  60      /* blocksize  */
  362. #define EPHE_CHIRON "CHI_"        /* file name prefix */
  363. #define EPHE_CHIRON_BSIZE 12      /* blocksize  */
  364.  
  365. /********************************************
  366. About the format of the ephemeris files
  367. ----------------------------------------
  368. We use currently ephemeris files with steps of 80 days.
  369. There are 1250 "records" in each file, so that one file
  370. spans 100000 days.
  371. We have two types of ephemeris files:
  372. LRZ5_nn   for the outer planets Jupiter ... Pluto
  373. CHI_nn  for Chiron.
  374. nn is an expression derived from the first julian daynumber on the
  375. file. Jd 2100'000 to 2199'920 is on file LRZ5_21 and CHI_21;
  376. for negative Jd we use the filenames LRZ5_Mxx  with M indicating the minus.
  377.  
  378. Given the jd for which you want the ephemeris, it is simple to build
  379. the filename and use fseek() within the file to go where the data is.
  380. This is done by the functions lrz_file_posit() and chi_file_posit().
  381.  
  382. The stored coordinates are for each date and planet:
  383. L = ecliptic longitude relative to mean exquinox of date,
  384. in units of milliseconds of acr (1/3600000 degree) as type long;
  385. R = radius vector, units of 10-7 AU, as type long.
  386. Z = disctance of ecliptic; Z = R * sin(latitude); in units of 10-7 AU,
  387. as type long.
  388. The data is stored in the byte ordering of the Astrodienst HPUX machines,
  389. which is most significant byte first. It is not the same byte ordering
  390. as on Intel processors; the function longreorder() converts between
  391. the disk file format and the internal format of MSDOS machines.
  392.  
  393. For LRZ5- files, we have 60-byte records LRZ(Jupiter),LRZ(Saturn),
  394. LRZ(Uranus), LRZ(Neptune), LRZ(Pluto). 
  395. For CHI-files we have 12-byte records LRZ.
  396.  
  397. ************************************************/
  398.  
  399.  
  400. /*************************************************************
  401. placalc2.c definitions
  402. *************************************************************/
  403.  
  404. #define SDNUM 20
  405. #define NUM_MOON_CORR 93
  406.  
  407. struct eledata {
  408. REAL8 axis,   /* mean distance, in a.u., A(N) in basic */
  409. period,   /* days for one revolution, P(N) in basic */
  410. epoch,    /* relative juldate of epoch, Ep(N) in basic */
  411. /* T = distance to epoch in jul.centuries 36525 day*/
  412. lg0,lg1,lg2,lg3,/* deg(epoch), degree/day, seconds/T^2,seconds/T^3 */
  413. /* Pd(N,0..2) in basic, lg3 was not present */
  414. pe0,pe1,pe2,pe3,/* deg(epoch), seconds/T,  seconds/T^2,seconds/T^3 */
  415. /* Pd(N,3..5) in basic, pe3 was not present */
  416. ex0,ex1,ex2,  /* ecl(epoch), 1/T, 1/T^2 */
  417. /* Pd(N,6..8) in basic */
  418. kn0,kn1,kn2,kn3,/* node(epoch),seconds/T,  seconds/T^2,seconds/T^3 */
  419. /* Pd(N,9..11) in basic, kn3 was not present */
  420. in0,in1,in2;    /* incl(epoch),1/T, 1/T^2 */
  421. /* Pd(N,12..14) in basic */
  422. };
  423.  
  424. struct kor {
  425.   int     j, i;
  426.   REAL8   lampl;  /* amplitude of disturbation in long, seconds of arc */
  427.   REAL8 lphase;   /* phase of disturbation in long, degrees */
  428.   INT4    rampl;  /* ampl. of disturbation in radius, 9th place of log */
  429.   REAL8   rphase; /* phase of disturbation in radius, degrees */
  430.   int     k;      /* index into disturbing planet anomaly table sa[] */
  431. };
  432.  
  433. struct sdat {   /* 0..19 mean anomalies of disturbing planets 
  434.   Sd(0..19,0..1) in basic */
  435.   REAL8 sd0,  /* mean anomaly at epoch 1850 */
  436.   sd1;  /* degrees/year */
  437. };
  438.  
  439. /* moon correction data; revised 30-jul-88: all long. to 0.3" */
  440. struct m45dat {   
  441.   int  i0,i1,i2,i3;
  442.   REAL8 lng,lat,par;
  443. };
  444.  
  445. extern struct eledata pd[MARS + 1];
  446. extern struct kor earthkor[];
  447. extern struct kor mercurykor[];
  448. extern struct kor venuskor[];
  449. extern struct kor marskor[];
  450. extern struct sdat _sd [SDNUM];
  451. extern struct m45dat m45[NUM_MOON_CORR];
  452. extern REAL8 rmima[CALC_N][2];  
  453. extern REAL8 ekld[4];
  454. extern REAL8 sa[SDNUM];
  455. extern double degnorm(double);
  456.  
  457. /*******************************************
  458. $Header: astrolib.h,v 1.2 91/11/16 16:21:02 alois Exp $
  459. astrolib.h
  460.  
  461. *******************************************/
  462.  
  463. /* macros for bit operations */
  464.  
  465. #define clear_bit(v,bit_nr) ((v) & ~(1L << (bit_nr)))
  466. #define set_bit(v,bit_nr)   ((v) | (1L << (bit_nr)))
  467. #define bit(bit_nr)         (1L << (bit_nr))
  468. #define check_bit(v,bit_nr) ((v) & (1L << (bit_nr)))
  469.  
  470. #endif /* PLACALC */
  471.  
  472. /* placalc.h */
  473.